import { reqGoodsDetail,reqAddGoodOrUpdate } from "@/api"
// 用于游客临时身份标识
import { getUUID } from "@/utils/uuid"
const state = {
    // 商品信息列表
    goodDetailList:{}
}
const actions = {
    async goodsDetail({commit},goodId){
        const result = await reqGoodsDetail(goodId)
        if(result.code === 200) commit('GOODSDETAIL',result.data)
    },
    // 添加商品到购物车之前，先给服务器发送信息储存数据
    async addGoodOrUpdate({commit},params){
        const result = await reqAddGoodOrUpdate(params)
        if(result.code===200) return 'ok'
        else return Promise.reject(new Error('fail'))
    }
}
const mutations = {
    GOODSDETAIL(state,data){
        state.goodDetailList = data
    }
}
const getters = {
    // 注意此处的state指当前的state
    categoryView:state=>state.goodDetailList.categoryView || {},
    skuInfo:state=>state.goodDetailList.skuInfo || {},
    spuSaleAttrList:state=>state.goodDetailList.spuSaleAttrList || []
}

export default {state,actions,mutations,getters}